Question: 1 -
Please select the correct expression to reassign a global variable “x” to 20 inside a function fun1()x = 50
def fun1():
# your code to assign global x = 20
fun1()
print(x) # it should print 20
-
global var x x = 20 -
global x =20 -
global.x = 20 -
global x x = 20
Answer:
global x
x = 20
Solution not available.
Question: 2 -
What is the data type of print(type(0xFF))
-
hexint
-
hex
-
int
-
number
Answer:
0bor0Bfor Binary and base is 20oor0Ofor Octal and base is 80xor0Xfor Hexadecimal and base is 16
int
Solution:
We can represent integers in binary, octal and hexadecimal formats.
We can represent integers in binary, octal and hexadecimal formats.
Question: 3 -
In Python 3, what is the output of type(range(5)). (What data type it will return).
-
None
-
range
-
int
-
list
Answer:
range
Solution not available.
Question: 4 -
What is the output of the following codedef func1():
x = 50
return x
func1()
print(x)
-
0
-
NameError
-
None
-
50
Answer:
NameError
Solution:
You will get a NameError: name 'x' is not defined. To access the function’s return value we must accept it using an assignment operator like this
def myfunc():
x = 50
return x
x = myfunc()
print(x)
You will get a NameError: name 'x' is not defined. To access the function’s return value we must accept it using an assignment operator like this
def myfunc():
x = 50
return x
x = myfunc()
print(x)
Question: 5 -
What is the data type of the followingaTuple = (1, 'Jhon', 1+3j)
print(type(aTuple[2:3]))
-
int
-
list
-
tuple
-
complex
Answer:
tuple
Solution:
When we access a tuple using the subscript atuple[start : end] operator, it will always return a tuple. We also call it tuple slicing. (taking a subset of a tuple using the range of indexes).
When we access a tuple using the subscript atuple[start : end] operator, it will always return a tuple. We also call it tuple slicing. (taking a subset of a tuple using the range of indexes).